using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;


namespace Test{

public partial class test : System.Web.UI.Page{

  private void Page_Load(object sender, System.EventArgs e){
    if(!IsPostBack){
        DataGrid1.DataSource = GetCustomers();
        DataGrid2.DataSource = GetSales();
        DataGrid1.DataBind();
        DataGrid2.DataBind();
        DropDownList1.DataTextField = "CustName";
        DropDownList1.DataSource = GetCustomers();
        DropDownList1.DataBind();
    }

}

public System.Data.DataSet GetCustomers() {
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=D:\\Documents an" +
                "d Settings\\Mina\\My Documents\\DBTest.mdb";
            System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);

            string queryString = "SELECT [Customers].* FROM [Customers]";
            System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
            dbCommand.CommandText = queryString;
            dbCommand.Connection = dbConnection;

            System.Data.IDbDataAdapter dataAdapter = new System.Data.OleDb.OleDbDataAdapter();
            dataAdapter.SelectCommand = dbCommand;
            System.Data.DataSet dataSet = new System.Data.DataSet();
            dataAdapter.Fill(dataSet);

            return dataSet;
        }

private System.Data.DataSet GetSales() {
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=D:\\Documents an" +
                "d Settings\\Mina\\My Documents\\DBTest.mdb";
            System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);

            string queryString = "SELECT [Sales].* FROM [Sales]";
            System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
            dbCommand.CommandText = queryString;
            dbCommand.Connection = dbConnection;

            System.Data.IDbDataAdapter dataAdapter = new System.Data.OleDb.OleDbDataAdapter();
            dataAdapter.SelectCommand = dbCommand;
            System.Data.DataSet dataSet = new System.Data.DataSet();
            dataAdapter.Fill(dataSet);

            return dataSet;
        }

        public int MyInsertMethod(string custName, string custID) {
            string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=D:\\Documents an" +
                "d Settings\\Mina\\My Documents\\DBTest.mdb";
            System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);

            string queryString = "INSERT INTO [Customers] ([CustName], [CustID]) VALUES (@CustName,@CustID)";
            System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
            dbCommand.CommandText = queryString;
            dbCommand.Connection = dbConnection;

            System.Data.IDataParameter dbParam_custName = new System.Data.OleDb.OleDbParameter();
            System.Data.IDataParameter dbParam_custID = new System.Data.OleDb.OleDbParameter();
            dbParam_custName.ParameterName = "@CustName";
            dbParam_custID.ParameterName = "@CustID";
            dbParam_custName.Value = custName;
            dbParam_custID.Value = custID;
            dbParam_custName.DbType = System.Data.DbType.String;
            dbParam_custID.DbType = System.Data.DbType.Int32;
            dbCommand.Parameters.Add(dbParam_custName);
            dbCommand.Parameters.Add(dbParam_custID);

            int rowsAffected = 0;
            dbConnection.Open();
            try {
                rowsAffected = dbCommand.ExecuteNonQuery();
            }
            finally {
                dbConnection.Close();
            }

            return rowsAffected;
        }



  }
 }
